//
//  MyMoneyVController.m
//  Experss
//
//  Created by 嗯，大葱 on 17/8/9.
//  Copyright © 2017年 嗯，大葱. All rights reserved.
//

#import "MyMoneyVController.h"
#import "MyTwoCell.h"
#import "ChongZhiVController.h"//充值
#import "TiXianViewController.h"//提现

#import "MyBankCardController.h"

#import "MingXiViewController.h"


@interface MyMoneyVController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong)UIButton *rightBtn2;//右侧按钮

@end

@implementation MyMoneyVController
-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    [[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 0;
    self.navigationItem.title = @"我的钱包";
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:16],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
     [self getBanace];
    
}
- (void)getBanace {
    NSDictionary *saveDic = [SaveDataMethord readLoginData];
    NSDictionary *parameDic = @{@"userid":saveDic[@"userid"],@"actoken":[Md5Apiway getMD5data:saveDic[@"userid"]]};
    [HttpRequest getWithURLString:POST(Shop_PersonalGetUserBalance) parameters:parameDic success:^(id responseObject) {
        if ([responseObject[@"ret"] intValue] != 200) {
            [MBProgressHUD showText:@"获取余额出错"];
            return ;
        }
        NSDictionary *tempD = responseObject[@"data"];
        if (![[NSString stringWithFormat:@"%@",tempD[@"code"]] isEqualToString:@"0"]) {
            [MBProgressHUD showText:tempD[@"msg"]];
            return;
        }
        
        _moneyLB.text = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"info"][@"balance"]];
       // _shengYuMoenyLB.text = [NSString stringWithFormat:@"%@元",moneyStr];
        
    } failure:^(NSError *error) {
        
    }];
    
    
}


- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = 1;
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont systemFontOfSize:16],
       NSForegroundColorAttributeName:[UIColor blackColor]}];
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self configureNaBar];
    _tableView.separatorStyle = kSpNone;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"MyTwoCell" bundle:nil] forCellReuseIdentifier:@"MyTwoCell"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSArray *titA = @[@"充值",@"提现",@"我的银行卡"];
    MyTwoCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyTwoCell"];
    cell.selectionStyle = kSeNone;
    cell.titLB.text = titA[indexPath.row];
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        ChongZhiVController *chong = [[ChongZhiVController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:chong animated:YES];
    }
    if (indexPath.row == 1) {
        TiXianViewController *chong = [[TiXianViewController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:chong animated:YES];
    }
    if (indexPath.row == 2) {
        MyBankCardController *chong = [[MyBankCardController alloc] init];
        chong.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:chong animated:YES];
    }
}

- (void)configureNaBar {

    //设置导航栏按钮的边距
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame= CGRectMake(0, 0, 60, 30);
    [rightBtn setImage:[UIImage imageNamed:@"all_fanhuibai"] forState:(UIControlStateNormal)];
    [rightBtn addTarget:self action:@selector(handleBackAxtion) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *btn_left = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    UIBarButtonItem *negativeSpacerleft = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    /**
     width为负数时，相当于btn向右移动width数值个像素，由于按钮本身和  边界间距为5pix，所以width设为-5时，间距正好调整为0；width为正数 时，正好相反，相当于往左移动width数值个像素
     */
    negativeSpacerleft.width = -20;
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:negativeSpacerleft, btn_left, nil];
    
    
    //设置导航栏按钮的边距
    _rightBtn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    _rightBtn2.frame= CGRectMake(0, 0, 60, 30);
    [_rightBtn2 setTitle:@"明细" forState:(UIControlStateNormal)];
    [_rightBtn2 addTarget:self action:@selector(mingxiAction) forControlEvents:UIControlEventTouchUpInside];
    _rightBtn2.titleLabel.font = kFont16;
    [_rightBtn2 setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    UIBarButtonItem *btn_right = [[UIBarButtonItem alloc] initWithCustomView:_rightBtn2];
    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace   target:nil action:nil];
    negativeSpacer.width = -20;
    self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:negativeSpacer, btn_right, nil];
    
}

- (void)handleBackAxtion {
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//明细按钮点击事件
- (void)mingxiAction {
    MingXiViewController *min = [[MingXiViewController alloc] init];
    [self.navigationController pushViewController:min animated:YES];
}

@end
